﻿using Developer.Core.FrameWork.GlobalVar;
using Developer.Core.FrameWork.HelpFile;
using Developer.Core.FrameWork.RedisExtensions.RedisSubscribeHandling;
using Developer.Core.FrameWork.RedisExtensions.RedisSubscribeInit.InitMq;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Developer.Core.FrameWork.RedisExtensions.Extensions
{
    /// <summary>
    /// Redis消息队列扩展类
    /// </summary>
    public static class RedisMQServiceCollectionExtensions
    {
        public static IServiceCollection AddRedisMQ(this IServiceCollection services)
        {
            // 0、是否开启RedisMQ服务订阅
            if (!GlobalVars.RedisMQ)
                return services;

            if (services == null) throw new ArgumentNullException(nameof(services));

            InitMqOption option = Appsettings.app<InitMqOption>("RedisConfig");
             
            services.AddInitRedisMq(m =>
            {
                //时间间隔
                m.SuspendTime = option.SuspendTime;
                //redis服务器地址
                m.ConnectionString = option.ConnectionString;
                //对应的订阅者类，需要new一个实例对象，当然你也可以传参，比如日志对象
                m.ListSubscribe = new List<Type>() { typeof(RedisSubscribe) };
                //显示日志
                m.ShowLog = option.ShowLog;
            });

            return services;
        }
    }
}
